layui.define(['notice'], function(exports) {
	var $ = layui.$;
	var notice = layui.notice;
	/**
	 * $_GET get参数 跟php中$_GET 一样
	 */
	window.$_GET = function() {
		var url = window.document.location.href.toString(); //当前完整url
		var u = url.split("?"); //以？为分隔符把url转换成字符串数组
		if (typeof(u[1]) == "string") {
			u = u[1].split("&"); //同上
			var get = {};
			for (var i in u) {
				var j = u[i].split("="); //同上
				get[j[0]] = j[1];
			}
			return get;
		} else {
			return {};
		}
	}();

	window.noticeMsg = function(type, msg) {
		switch (type) {
			case 'warning':
				layer.alert(msg);
				break;
			case 'error':
				layer.msg(msg, {
					anim : 6,
					icon : 2
				});	
				break;
			case 'success':
				layer.msg(msg, {
					icon : 1
				});
				break;
			default:
				layer.msg(msg);
				break;
		}
	}
	
	//打印debug信息
	window.debug = function(msg,  type = 'log'){
		if(appConfig.appDbug === true){
			var evalstr = "console."+type+"(msg)";
			eval(evalstr);
			//alert(evalstr);
		}
	}
	/**
	 * 设置/删除cookie
	 * @param name
	 * @param value
	 * @param time
	 * @returns
	 */
	window.setcookie = function(name, value, time) {
		var exp = new Date();
		if (null == value) {
			exp.setTime(0);
		} else {
			exp.setTime(exp.getTime() + time * 1000);
		}
		document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
	}
	/**
	 * 获取cookie
	 * @param name
	 * @returns
	 */
	window.getcookie = function(name) {
		var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
		if (arr = document.cookie.match(reg)) {
			return unescape(arr[2]);
		} else {
			return null;
		}
	}

	window.submit_request = function(url, method, data, successCallback, errorCallback) {
		var index = layer.load(1, {
			shade: [0.3, '#000'] //0.1透明度的白色背景
		});
		var request = $.ajax({
			url: url,
			method: method,
			timeout: 30000,
			data: data,
			dataType: 'json',
			mimeType: "multipart/form-data",
			processData: false,
			contentType: false
		});

		request.done(function(res) {
			layer.close(index);
			debug(res);
			var code = res.errorcode;
			var msg = res.errormsg;
			var url = res.url;
			if (!is_json(res)) {
				return successCallback(res);
			}
			if (code == 0) {
				if (successCallback == undefined) {
					notice.success(msg);
				} else {
					successCallback(res);
				}

			} else {
				if (errorCallback == undefined) {
					notice.error(msg);
				} else {
					errorCallback(res);
				}
			}
		});

		request.fail(function(jqXHR) {
			layer.close(index);
			console.error(jqXHR);
			if (jqXHR.responseJSON && jqXHR.responseJSON.errormsg) {
				
				if (errorCallback == undefined) {
					if(jqXHR.responseJSON.errormsg){
						notice.error(jqXHR.responseJSON.errormsg);
					}else{
						notice.error(json_encode(jqXHR.responseJSON));
					}
				} else {
					errorCallback(jqXHR.responseJSON);
				}
				
				if(jqXHR.responseJSON.errorcode == 10001){
					sessionStorage.clear();
					window.location = appRoute.login;
				}
				
			} else {
				if (jqXHR.responseText) {
					alert(jqXHR.responseText);
				} else {
					alert(jqXHR.statusText);
				}
			}
		});
	};

	/**
	 * ajax请求
	 * @param {Object} url
	 * @param {Object} method
	 * @param {Object} data
	 * @param {Object} successCallback
	 * @param {Object} errorCallback
	 */
	window.ajax_request = function(url, method, data, successCallback, errorCallback) {
		var index = layer.load(1, {
			shade: [0.6, '#000'] //0.1透明度的白色背景
		});
		var request = $.ajax({
			url: url,
			method: method,
			timeout: 30000, // 超时时间设置，单位毫秒
			data: data,
			//dataType: 'json'
		});

		request.done(function(res) {
			layer.close(index);
			debug(res);
			var code = res.errorcode;
			var msg = res.errormsg;
			var url = res.url;
			if (!is_json(res)) {
				return successCallback(res);
			}
			if (code == 0) {
				if (successCallback == undefined) {
					notice.success(msg);
				} else {
					successCallback(res);
				}

			} else {
				if (errorCallback == undefined) {
					notice.error(msg);
				} else {
					errorCallback(res);
				}
			}
		});

		request.fail(function(jqXHR) {
			layer.close(index);
			console.error(jqXHR);
			if (jqXHR.responseJSON) {
				if(jqXHR.responseJSON.errorcode == 10001){
					sessionStorage.clear();
					window.location = appRoute.login;
				}
				if (errorCallback == undefined) {
					if(jqXHR.responseJSON.errormsg){
						notice.error(jqXHR.responseJSON.errormsg);
					}else{
						notice.error(json_encode(jqXHR.responseJSON));
					}
					
				} else {
					errorCallback(jqXHR.responseJSON);
				}
			} else {
				if (jqXHR.responseText) {
					alert(jqXHR.responseText);
				} else {
					alert(jqXHR.statusText);
				}
			}
		});
	};
	//打开一个url
	window.openUrl = function(obj, callback) {
		if (callback == undefined) {
			callback = function(){};
		}
		layer.open({
			type: 2,
			title: obj.getAttribute('data-title'),
			shadeClose: true,
			shade: 0.7,
			scrollbar: false,
			offset: 'r',
			area: ['50%', '100%'],
			content: obj.getAttribute("data-url"),
			cancel: callback()
		});
	};
	//执行后是否跳转url
	window.submitUrl = function(obj, url) {
		layer.confirm('确定要' + obj.getAttribute('data-title') + "?", function(index) {
			var successCallback = undefined;
			if (typeof url != "undefined") {
				window.tempUrl = url;
				successCallback = function(res) {
					window.location = tempUrl;
				}
			}
			ajax_request(obj.getAttribute("data-url"), 'POST', '', successCallback);
		});
	};
	/**
	 * 图片预览
	 * @param {Object} obj
	 */
	window.pictureBrowser = function(obj) {
		
        var img_url = obj.src;

        // 创建对象
        var img = new Image();

        // 改变图片的src
        img.src = img_url;
        
        var width = img.width;
        
        if(width > $(window).width()){
        	width = $(window).width();
        }
		
		layer.open({
			type: 1,
			title: '图片预览',
			scrollbar: false,
			shadeClose: true,
			shade: 0.3,
			area: [width+'px', '600px'],
			content: '<img src="' + obj.src + '"  />', //iframe的url
		});
	}

	/**
	 * 视频预览
	 * @param {Object} obj
	 */
	window.videoBrowser = function(obj) {
		layer.open({
			type: 2,
			title: '视频预览',
			scrollbar: false,
			shadeClose: true,
			shade: 0.3,
			area: ['500px', '100%'],
			content: './finder/video.html?url=' + $(obj).data('url'), //iframe的url
		});
	}
	window.audioBrowser = function(obj) {
		layer.open({
			type: 1,
			title: '音频预览',
			shadeClose: true,
			scrollbar: false,
			shade: 0.3,
			area: ['auto', 'auto'],
			content: '<audio controls="controls" autoplay="autoplay">\
  <source src="song.ogg" type="audio/ogg">\
  <source src="' +
				$(obj).data('url') + '" type="audio/mpeg">\
Your browser does not support the audio tag.\
</audio>', //iframe的url
		});
	}
	/**
	 * 判断两个数据是否相等
	 * @param {Object} arr1
	 * @param {Object} arr2
	 */
	window.arrayEqual = function(arr1, arr2) {
		if (arr1 === arr2) return true;
		if (arr1.length != arr2.length) return false;
		for (var i = 0; i < arr1.length; ++i) {
			if (arr1[i] !== arr2[i]) return false;
		}
		return true;
	};
	/**
	 * 判断是手机浏览器还是pc浏览器
	 */
	window.browserRedirect = function() {
		var sUserAgent = navigator.userAgent.toLowerCase();
		var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
		var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
		var bIsMidp = sUserAgent.match(/midp/i) == "midp";
		var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
		var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
		var bIsAndroid = sUserAgent.match(/android/i) == "android";
		var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
		var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
		if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
			//是PC浏览器
			return 'pc';
		} else {
			//是移动浏览器
			return 'wap';
		}
	};
	/**
	 * 取数组最大值
	 * 数组打乱
	 * @param {Object} arr
	 */
	window.upsetArr = function(arr) {
		return arr.sort(function() {
			return Math.random() - 0.5;
		});
	};
	/**
	 * 取数组最小值
	 * @param {Object} arr
	 */
	window.maxArr = function(arr) {
		return Math.max.apply(null, arr);
	};
	/**
	 * 取数组最小值
	 * @param {Object} arr
	 */
	window.minArr = function(arr) {
		return Math.min.apply(null, arr);
	};
	/**
	 * 从数组中随机获取元素
	 * @param {Object} arr
	 */
	window.randomOne = function(arr) {
		return arr[Math.floor(Math.random() * arr.length)]
	};
	/**
	 * 返回数组（字符串）出现最多的几次元素和出现次数
	 * @param arr
	 * @param rank
	 * @param ranktype
	 * @returns
	 * 实例 getCount([1,2,3,1,2,5,2,4,1,2,6,2,1,3,2])
	 */
	window.getCount = function(arr, rank, ranktype) {
		var obj = {},
			k, arr1 = [];
		//记录每一元素出现的次数
		for (var i = 0; i < arr.length; i++) {
			k = arr[i];
			if (obj[k]) {
				obj[k]++
			} else {
				obj[k] = 1;
			}
		}
		//保存结果{el-'元素'，count-出现次数}
		for (var o in obj) {
			arr1.push({
				'el': o,
				'count': obj[o]
			})
		}
		//排序（升序）
		arr1.sort(function(a, b) {
			return a['count'] - b['count']
		})
		//如果ranktype为真
		if (ranktype) {
			arr1.reverse();
		}

		var rank1 = rank || arr1.length;
		return arr1.slice(0, rank1);
	};
	/**
	 * 删除左边第一个字符
	 * @param {Object} str
	 */
	window.ltrim = function(str) {
		return str.substr(1, str.length);
	};
	/**
	 * 删除右边第一个字符
	 * @param {Object} str
	 */
	window.rtrim = function(str) {
		return str.substr(0, str.length - 1);
	};
	/**
	 * 返回字符串的长度
	 * @param {Object} str
	 */
	window.strlen = function(str) {
		return str.length;
	};
	/**
	 * 移动设备类型判断
	 * @param {Object} type
	 */
	window.mobileDevice = function(type) {
		var ua = navigator.userAgent.toLowerCase();
		switch (type) {
			case 'android':
				return ua.indexOf('android') !== -1
			case 'iphone':
				return ua.indexOf('iphone') !== -1
			case 'ipad':
				return ua.indexOf('ipad') !== -1
			case 'weixin':
				return ua.indexOf('MicroMessenger') !== -1
			default:
				return ua
		}
	};

	/**
	 * 到某一个时间的倒计时
	 * @param endtime
	 * @returns
	 * 实例 setInterval(function(){
			    getEndTime('2018/04/06 14:00');
			},1000)
	 */
	window.getEndTime = function(endtime) {
		var startDate = new Date();
		var endDate = new Date(endtime);

		var t = endDate - startDate;
		var d, h, m, s = 0;
		if (t > 0) {
			d = format(Math.floor(t / 1000 / 3600 / 24));
			h = format(Math.floor(t / 1000 / 3600 % 24));
			m = format(Math.floor(t / 1000 / 60 % 60));
			s = format(Math.floor(t / 1000 % 60));
		}

		function format(num) {
			return num.toString().replace(/^(\d)$/, '0$1');
		}
		//console.log(d,h,m,s)
	};



	/**
	 * 获取域名主机 params: url:域名
	 */
	window.getHost = function(url) {
		var host = "null";
		if (typeof url == "undefined" || null == url) {
			url = window.location.href;
		}
		var regex = /^\w+\:\/\/([^\/]*).*/;
		var match = url.match(regex);
		if (typeof match != "undefined" && null != match) {
			host = match[1];
		}
		return host;
	};
	/**
	 * 转义html标签
	 */
	window.htmlEncode = function(text) {
		return text.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g,
			'<').replace(/>/g, '>');
	};
	/**
	 * 还原html标签
	 */
	window.htmlDecode = function(text) {
		return text.replace(/&/g, '&').replace(/"/g, '\"').replace(
			/</g, '<').replace(/>/g, '>');
	};
	/**
	 * 加入收藏夹
	 */
	window.AddFavorite = function(sURL, sTitle) {
		try {
			window.external.addFavorite(sURL, sTitle);
		} catch (e) {
			try {
				window.sidebar.addPanel(sTitle, sURL, "");
			} catch (e) {
				alert("加入收藏失败，请使用Ctrl+D进行添加");
			}
		}
	};
	/**
	 * 设为首页
	 */
	window.setHomepage = function() {
		if (document.all) {
			document.body.style.behavior = 'url(#default#homepage)';
			document.body.setHomePage('http://***');
		} else if (window.sidebar) {
			if (window.netscape) {
				try {
					netscape.security.PrivilegeManager
						.enablePrivilege("UniversalXPConnect");
				} catch (e) {
					alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
				}
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', 'http://***');
		}
	};
	/**
	 * 动态加载 CSS 样式文件
	 */
	window.LoadStyle = function(url) {
		try {
			document.createStyleSheet(url);
		} catch (e) {
			var cssLink = document.createElement('link');
			cssLink.rel = 'stylesheet';
			cssLink.type = 'text/css';
			cssLink.href = url;
			var head = document.getElementsByTagName('head')[0];
			head.appendChild(cssLink);
		}
	};
	/**
	 * 返回浏览器版本
	 * 
	 * 返回一个对象,对象属性：type，version
	 */
	window.getExplorerInfo = function() {
		var explorer = window.navigator.userAgent.toLowerCase();
		// ie
		if (explorer.indexOf("msie") >= 0) {
			var ver = explorer.match(/msie ([\d.]+)/)[1];
			return {
				type: "IE",
				version: ver
			};
		}
		// firefox
		else if (explorer.indexOf("firefox") >= 0) {
			var ver = explorer.match(/firefox\/([\d.]+)/)[1];
			return {
				type: "Firefox",
				version: ver
			};
		}
		// Chrome
		else if (explorer.indexOf("chrome") >= 0) {
			var ver = explorer.match(/chrome\/([\d.]+)/)[1];
			return {
				type: "Chrome",
				version: ver
			};
		}
		// Opera
		else if (explorer.indexOf("opera") >= 0) {
			var ver = explorer.match(/opera.([\d.]+)/)[1];
			return {
				type: "Opera",
				version: ver
			};
		}
		// Safari
		else if (explorer.indexOf("Safari") >= 0) {
			var ver = explorer.match(/version\/([\d.]+)/)[1];
			return {
				type: "Safari",
				version: ver
			};
		}
	};
	/**
	 * 检验URL链接是否有效
	 * 
	 * .Open("GET",URL, false) true:异步；false:同步
	 */
	window.getUrlState = function(URL) {
		var suc = false;
		var xmlhttp = new ActiveXObject("microsoft.xmlhttp");
		xmlhttp.Open("GET", URL, false);
		try {
			xmlhttp.Send();
		} catch (e) {} finally {
			var result = xmlhttp.responseText;
			if (result) {
				if (xmlhttp.Status == 200) {
					suc = true;
				} else {
					suc = false;
				}
			} else {
				suc = false;
			}
		}
		return suc;
	};
	/**
	 * 格式化CSS样式代码
	 */
	window.formatCss = function(s) { // 格式化代码
		s = s.replace(/\s*([\{\}\:\;\,])\s*/g, "$1");
		s = s.replace(/;\s*;/g, ";"); // 清除连续分号
		s = s.replace(/\,[\s\.\#\d]*{/g, "{");
		s = s.replace(/([^\s])\{([^\s])/g, "$1 {\n\t$2");
		s = s.replace(/([^\s])\}([^\n]*)/g, "$1\n}\n$2");
		s = s.replace(/([^\s]);([^\s\}])/g, "$1;\n\t$2");
		return s;
	};
	/**
	 * 压缩CSS样式代码
	 */
	window.yasuoCss = function(s) { // 压缩代码
		s = s.replace(/\/\*(.|\n)*?\*\//g, ""); // 删除注释
		s = s.replace(/\s*([\{\}\:\;\,])\s*/g, "$1");
		s = s.replace(/\,[\s\.\#\d]*\{/g, "{"); // 容错处理
		s = s.replace(/;\s*;/g, ";"); // 清除连续分号
		s = s.match(/^\s*(\S+(\s+\S+)*)\s*$/); // 去掉首尾空白
		return (s == null) ? "" : s[1];
	};
	/**
	 * 获取当前路径
	 */
	window.getCurrentPageUrl = function() {
		var currentPageUrl = "";
		if (typeof this.href === "undefined") {
			currentPageUrl = document.location.toString().toLowerCase();
		} else {
			currentPageUrl = this.href.toString().toLowerCase();
		}
		return currentPageUrl;
	};
	/**
	 * ip 转 整型
	 */
	window._ip2int = function(ip) {
		var num = 0;
		ip = ip.split(".");
		num = Number(ip[0]) * 256 * 256 * 256 + Number(ip[1]) * 256 * 256 +
			Number(ip[2]) * 256 + Number(ip[3]);
		num = num >>> 0;
		return num;
	};
	/**
	 * 整型解析为IP地址
	 */
	window._int2iP = function(num) {
		var str;
		var tt = new Array();
		tt[0] = (num >>> 24) >>> 0;
		tt[1] = ((num << 8) >>> 24) >>> 0;
		tt[2] = (num << 16) >>> 24;
		tt[3] = (num << 24) >>> 24;
		str = String(tt[0]) + "." + String(tt[1]) + "." + String(tt[2]) + "." +
			String(tt[3]);
		return str;
	};
	/**
	 * 判断是否移动设备访问
	 */
	window.isMobileUserAgent = function() {
		return (/iphone|ipod|android.*mobile|windows.*phone|blackberry.*mobile/i
			.test(window.navigator.userAgent.toLowerCase()));
	}

	/**
	 * 判断是否苹果移动设备访问
	 */
	window.isAppleMobileDevice = function() {
		return (/iphone|ipod|ipad|Macintosh/i.test(navigator.userAgent
			.toLowerCase()));
	};

	/**
	 * 判断是否安卓移动设备访问
	 */
	window.isAndroidMobileDevice = function() {
		return (/android/i.test(navigator.userAgent.toLowerCase()));
	};

	/**
	 * 判断是否Touch屏幕
	 */
	window.isTouchScreen = function() {
		return (('ontouchstart' in window) || window.DocumentTouch &&
			document instanceof DocumentTouch);
	};

	/**
	 * 判断是否在安卓上的谷歌浏览器
	 */
	window.isNewChromeOnAndroid = function() {
		if (this.isAndroidMobileDevice()) {
			var userAgent = navigator.userAgent.toLowerCase();
			if ((/chrome/i.test(userAgent))) {
				var parts = userAgent.split('chrome/');

				var fullVersionString = parts[1].split(" ")[0];
				var versionString = fullVersionString.split('.')[0];
				var version = parseInt(versionString);

				if (version >= 27) {
					return true;
				}
			}
		}
		return false;
	};

	/**
	 * 判断是否打开视窗
	 */
	window.isViewportOpen = function() {
		return !!document.getElementById('wixMobileViewport');
	};

	/**
	 * 获取移动设备初始化大小
	 */
	window.getInitZoom = function() {
		if (!this._initZoom) {
			var screenWidth = Math.min(screen.height, screen.width);
			if (this.isAndroidMobileDevice() && !this.isNewChromeOnAndroid()) {
				screenWidth = screenWidth / window.devicePixelRatio;
			}
			this._initZoom = screenWidth / document.body.offsetWidth;
		}
		return this._initZoom;
	};

	/**
	 * 获取移动设备最大化大小
	 */
	window.getZoom = function() {
		var screenWidth = (Math.abs(window.orientation) === 90) ? Math.max(screen.height, screen.width) : Math.min(screen.height,
			screen.width);
		if (this.isAndroidMobileDevice() && !this.isNewChromeOnAndroid()) {
			screenWidth = screenWidth / window.devicePixelRatio;
		}
		var FixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport;
		var FixViewPortsExperimentRunning = FixViewPortsExperiment && (FixViewPortsExperiment === "New" ||
			FixViewPortsExperiment === "new");
		if (FixViewPortsExperimentRunning) {
			return screenWidth / window.innerWidth;
		} else {
			return screenWidth / document.body.offsetWidth;
		}
	};
	/**
	 * 获取移动设备最大化大小
	 */
	window.getZoom = function() {
		var screenWidth = (Math.abs(window.orientation) === 90) ? Math.max(screen.height, screen.width) : Math.min(screen.height,
			screen.width);
		if (this.isAndroidMobileDevice() && !this.isNewChromeOnAndroid()) {
			screenWidth = screenWidth / window.devicePixelRatio;
		}
		var FixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport;
		var FixViewPortsExperimentRunning = FixViewPortsExperiment && (FixViewPortsExperiment === "New" ||
			FixViewPortsExperiment === "new");
		if (FixViewPortsExperimentRunning) {
			return screenWidth / window.innerWidth;
		} else {
			return screenWidth / document.body.offsetWidth;
		}
	};
	/**
	 * 获取移动设备屏幕宽度
	 */
	window.getScreenWidth = function() {
		var smallerSide = Math.min(screen.width, screen.height);
		var fixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport;
		var fixViewPortsExperimentRunning = fixViewPortsExperiment && (fixViewPortsExperiment.toLowerCase() === "new");
		if (fixViewPortsExperiment) {
			if (this.isAndroidMobileDevice() && !this.isNewChromeOnAndroid()) {
				smallerSide = smallerSide / window.devicePixelRatio;
			}
		}
		return smallerSide;
	};

	/**
	 * 完美判断是否为网址
	 */
	window.IsURL = function(strUrl) {
		var regular =
			/^\b(((https?|ftp):\/\/)?[-a-z0-9]+(\.[-a-z0-9]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|asia|coop|aero|[a-z][a-z]|((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d))\b(\/[-a-z0-9_:\@&?=+,.!\/~%\$]*)?)$/i;
		if (regular.test(strUrl)) {
			return true;
		} else {
			return false;
		}
	};
	/**
	 * 获取页面scrollLeft
	 */
	window.getPageScrollLeft = function() {
		var a = document;
		return a.documentElement.scrollLeft || a.body.scrollLeft;
	};


	/**
	 * 获取页面宽度
	 */
	window.getPageWidth = function() {
		var g = document,
			a = g.body,
			f = g.documentElement,
			d = g.compatMode == "BackCompat" ?
			a :
			g.documentElement;
		return Math.max(f.scrollWidth, a.scrollWidth, d.clientWidth);
	};

	window.getRatioWidth = function(Ratio, df){
		var pw = getPageWidth();
		var width = pw * Ratio;
		if(width >　df){
			return width;
		}else{
			return df;
		}
		
	}
	/**
	 * 获取页面scrollTop
	 */
	window.getPageScrollTop = function() {
		var a = document;
		return a.documentElement.scrollTop || a.body.scrollTop;
	};

	/**
	 * 获取页面可视高度
	 */
	window.getPageViewHeight = function() {
		var d = document,
			a = d.compatMode == "BackCompat" ?
			d.body :
			d.documentElement;
		return a.clientHeight;
	};
	/**
	 * 判断一个变量是否是数据
	 * @param arr
	 * @returns
	 */
	window.is_array = function(arr) {
		Array.isArray(arr);
	};
	/**
	 * 给数组里追加元素
	 * @param arr
	 * @param variable
	 * @returns
	 */
	window.array_push = function(arr, variable) {
		return arr.push(variable);
	};
	/**
	 * 数组翻转
	 * @param arr
	 * @returns
	 */
	window.array_reverse = function(arr) {
		return arr.reverse();
	};
	/**
	 * 数组中元素排序;(默认：从小到大) 
	 * var arr = [4,5,1,3,2,7,6];
	   var aaa =arr.sort();
	 * @returns
	 */
	window.array_sort = function(arr) {
		return arr.sort();
	};
	/**
	 * 合并数组
	 * @param arr1
	 * @param arr2
	 * @returns
	 */
	window.array_merge = function(arr1, arr2) {
		return arr1.concat(arr2);
	};

	/**
	 * 判断一个内容是否在一个数组中
	 * @param search
	 * @param array
	 * @returns
	 */
	window.in_array = function(search, array) {
		for (var i in array) {
			if (array[i] == search) {
				return true;
			}
		}
		return false;
	};
	/**
	 * 产生随机整数，包含下限值，但不包括上限值
	 * @param {Number} lower 下限
	 * @param {Number} upper 上限
	 * @return {Number} 返回在下限到上限之间的一个随机整数
	 */
	window.rand = function(lower, upper) {
		return Math.floor(Math.random() * (upper - lower)) + lower;
	};

	/**
	 * 获取当前时间戳
	 * @returns
	 */
	window.time = function() {
		var timestamp = new Date().getTime();
		return parseInt(timestamp / 1000);
	};
	/**
	 * 获取带微妙的时间戳
	 * @returns
	 */
	window.microtime = function() {
		var timestamp = new Date().getTime();
		return timestamp / 1000;
	};
	/**
	 * 时间格式方法
	 * 
	 * @param {any} timeStamp  时间戳，秒级/毫秒级
	 * @param {any} type 格式化时间类型，默认  Y-M-D H:I:S
	 * @returns {string} formatTime 格式化后的时间 例如： 2017-05-05 12:09:22
	 */
	window.formatDate = function(timeStamp, type = 'Y-M-D H:I:S', auto = false) {
		let time = (timeStamp + '').length === 10 ? new Date(parseInt(timeStamp) * 1000) : new Date(parseInt(timeStamp));
		let _year = time.getFullYear();
		let _month = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1);
		let _date = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
		let _hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
		let _minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
		let _secconds = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
		let formatTime = '';
		let distinctTime = new Date().getTime() - time.getTime();

		if (auto) {
			if (distinctTime <= (1 * 60 * 1000)) {
				// console.log('一分钟以内，以秒数计算');
				let _s = Math.floor((distinctTime / 1000) % 60);
				formatTime = _s + '秒前';
			} else if (distinctTime <= (1 * 3600 * 1000)) {
				// console.log('一小时以内,以分钟计算');
				let _m = Math.floor((distinctTime / (60 * 1000)) % 60);
				formatTime = _m + '分钟前';
			} else if (distinctTime <= (24 * 3600 * 1000)) {
				// console.log('一天以内，以小时计算');
				let _h = Math.floor((distinctTime / (60 * 60 * 1000)) % 24);
				formatTime = _h + '小时前';
			} else if (distinctTime <= (30 * 24 * 3600 * 1000)) {
				let _d = Math.floor((distinctTime / (24 * 60 * 60 * 1000)) % 30);
				formatTime = _d + '天前';
				// console.log('30天以内,以天数计算');
			} else {
				// 30天以外只显示年月日
				formatTime = _year + '-' + _month + '-' + _date;
			}
		} else {

			switch (type) {
				case 'Y-M-D H:I:S':
					formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
					break;
				case 'Y-M-D H:I:S zh':
					formatTime = _year + '年' + _month + '月' + _date + '日  ' + _hours + ':' + _minutes + ':' + _secconds;
					break;
				case 'Y-M-D H:I':
					formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes;
					break;
				case 'Y-M-D H':
					formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours;
					break;
				case 'Y-M-D':
					formatTime = _year + '-' + _month + '-' + _date;
					break;
				case 'Y-M-D zh':
					formatTime = _year + '年' + _month + '月' + _date + '日';
					break;
				case 'Y-M':
					formatTime = _year + '-' + _month;
					break;
				case 'Y':
					formatTime = _year;
					break;
				case 'M':
					formatTime = _month;
					break;
				case 'D':
					formatTime = _date;
					break;
				case 'H':
					formatTime = _hours;
					break;
				case 'I':
					formatTime = _minutes;
					break;
				case 'S':
					formatTime = _secconds;
					break;
				default:
					formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
					break;
			}
		}
		// 返回格式化的日期字符串
		return formatTime;
	};
	/**
	 * 将日期转时间戳
	 * @param str
	 * @returns
	 */
	window.strtotime = function(str) {
		var date = new Date(str);

		var time1 = date.getTime();

		return time1 / 1000;
	};
	/**
	 * session写入读取
	 * @param name
	 * @param value
	 * @returns
	 */
	window.session = function(name, value) {
		if (null == name) {
			sessionStorage.clear();
		} else if (null == value) {
			sessionStorage.removeItem(name);
		} else if (name != null && value != null) {
			sessionStorage.setItem(name, value);
		} else {
			return sessionStorage.getItem(name);
		}
	};
	/**
	 * 获取开始和结束值之间的随机数
	 * @param begin
	 * @param end
	 * @returns
	 */
	window.rand = function(begin, end) {
		var num = Math.round(Math.random() * (end - begin) + begin);
		return num;
	};
	/**
	 * 字符串拆分成数组
	 * @param {Object} str
	 * @param {Object} howmany
	 */
	window.str_split = function(str, howmany) {
		return str.split(howmany);
	};
	window.implode = function(delimiter, arr) {
		return arr.join(delimiter);
	}
	/**
	 * 字符串分割成数组
	 * @param {Object} delimiter
	 * @param {Object} str
	 */
	window.explode = function(delimiter, str) {
		return str.split(delimiter);
	};
	/**
	 * 字符串转大写
	 * @param {Object} str
	 */
	window.strtoupper = function(str) {
		return str.toUpperCase();
	};
	/**
	 * 字符串转小写
	 * @param {Object} str
	 */
	window.strtolower = function(str) {
		return str.toLowerCase();
	};
	/**
	 * 将字符串的首字母转换为大写
	 * @param {Object} str
	 */
	window.ucfirst = function(str) {
		str = str.trim();
		return str.replace(str[0], str[0].toUpperCase());
	};
	/**
	 * 计算指定字符串在目标字符串中最后一次出现的位置 判断的时候>= 0 
	 * @param {Object} str
	 * @param {Object} search
	 */
	window.strrpos = function(str, search) {
		return str.lastIndexOf(search);
	};
	/**
	 * 重复一个字符串
	 * @param {Object} str
	 * @param {Object} num
	 */
	window.str_repeat = function(str, num) {
		var newStr = '';
		for (i = 0; i < num; i++) {
			newStr += str;
		}
		return newStr;
	};
	/**
	 * 计算字串出现的次数
	 * @param {Object} str
	 * @param {Object} search
	 */
	window.substr_count = function(str, search) {
		var num = 0;
		try{
			num = (str.split(search)).length - 1;
		}catch(e){
			//TODO handle the exception
		}
		
		return num;
	};

	/**
	 * 字符串替换
	 * @param {Object} search
	 * @param {Object} replace
	 * @param {Object} subject
	 */
	window.str_replace = function(search, replace, subject) {
		for (i in search) {
			subject = subject.replace(new RegExp(search[i], 'g'), replace[i]);
		}
		return subject;
	};
	/**
	 * 字符串截取
	 * @param {Object} str
	 * @param {Object} start
	 * @param {Object} length
	 */
	window.substr = function(str, start, length) {
		return str.substr(start, length);
	};
	window.is_bool = function() {

	};
	window.is_float = function() {

	};
	window.is_int = function(val) {
		if (!isNaN(val)) {
			return true;
		} else {
			return false;
		}
	};
	window.is_null = function() {

	};
	window.is_numeric = function(val) {
		if (val === "" || val == null) {
			return false;
		}
		if (!isNaN(val)) {
			//对于空数组和只有一个数值成员的数组或全是数字组成的字符串，isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
			//所以如果不需要val包含这些特殊情况，则这个判断改写为if(!isNaN(val) && typeof val === 'number' )
			return true;
		} else {
			return false;
		}
	};
	window.is_object = function(obj) {
		if(obj instanceof Object){
			return true;
		}
		return false;
	};
	window.is_string = function(obj) {
		if(typeof(obj) == 'string')
		{
		    return true;
		}
		return false;
	};
	window.intval = function(val) {
		return parseInt(val);
	};
	window.floatval = function() {

	};
	window.strval = function() {

	};
	window.boolval = function() {

	};
	window.in_array = function(search, array) {
		for (var i in array) {
			if (array[i] == search) {
				return true;
			}
		}
		return false;
	}
	/**
	 * json编码成字符串
	 * @param {Object} obj
	 */
	window.json_encode = function(obj) {
		try{
			return JSON.stringify(obj);
		}catch(e){
			return '';
		}
		
	}

	window.empty = function(str) {
		if (typeof str == null || str == "" || str == "undefined" || str == 0 || str == '0' || str == 'null' || str ==
			null) {
			return true;
		} else {
			return false;
		}
	}
	window.is_json = function(str) {
		if (typeof str == 'string') {
			try {
				return JSON.parse(str);
			} catch (e) {
				return false;
			}
		}
		return false;
	}
	window.isset = function(obj) {
		try{
			if (typeof obj !== 'undefined') {
				return true;
			}
		}catch(e){
			return false;
		}
		
		return false;
	}
	
	window.count = function(arr){
		if(is_array(arr)){
			var num = 0;
			for(i in arr){
				num++;
			}
			return num;
		}
		return 0;
	}
	exports('helper', window); //导出
});
